﻿using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Logging;
using System.Collections.Generic;
using ZhaoXi_Core_WebApi.Utility;

namespace ZhaoXi_Core_WebApi.Controllers
{
    //webapi的控制器是严格遵循Restfull风格的
    [ApiController]
    [Route("[controller]")]
    public class FilterController : ControllerBase
    {


        private readonly ILogger<FilterController> _logger; //因为是注入嘛，所以默认情况 下是为空的

        public FilterController(ILogger<FilterController> logger)
        {
            _logger = logger;
        }



        [HttpGet("{id}")]  //http://localhost:5000/Filter/22
        [CustomActionFilter] //方法过滤器
        public string get(int id) 
        {
            return "dxf你是最棒的";
        }


        [HttpGet("{id},{name}")] //restful风格的请求参数要这么写 //http://localhost:5000/Filter/12,dxf
                                 //观察这三个filter的执行过程
        //[CustomExceptionFilter]//这么写是进入的无参的构造函数 （在CustomExceptionFilter里面写日志就会报错）
        //[TypeFilter(typeof(CustomExceptionFilterAttribute))] 方法上注册，改到start里面全局注册了
          [CustomActionFilter] //方法过滤器
        public int getname22(int id, string name)
        {
            int a = 0;
            return 10 / a;
        }
    }
}